<?php
require("../../../class2.php");
require("../library/admin/adminapi.php");

if(!getperms("P")){header("location:".e_BASE."index.php"); exit; }
require_once(e_ADMIN."auth.php");

//
// Process the Form
//
if($_POST["subbed"]) {
    e107shop_admin_process_validation($_POST["faction"], $_POST["vald_fname"], 
    $_POST["vald_lname"], $_POST["vald_email"], $_POST["vald_addr1"], $_POST["vald_city"], 
    $_POST["vald_state"], $_POST["vald_count"], $_POST["vald_region"], $_POST["vald_zip"]);
}

//
// Display the form
//
e107shop_manage_validation($_GET["a"]);

function e107shop_manage_validation($action) {
    global $sql, $ns, $e107shop_db_name;
    if($action==1 || $sql->db_Select($e107shop_db_name['validate'], "*", "")) {
        //
        //edit the product
        //
        $sql->db_Select($e107shop_db_name['validate'], "*", "");
        while($row=$sql->db_Fetch()) {
            //
            // Store the fields in variables so they can be
            // used in the form, without having to write out the
            // form twice.
            //
            $vald_fname = $row["vald_fname"];
            $vald_lname = $row["vald_lname"];
            $vald_email = $row["vald_email"];
            $vald_addr1 = $row["vald_addr1"];
            $vald_city = $row["vald_city"];
            $vald_state = $row["vald_state"];
            $vald_count = $row["vald_count"];
            $vald_region = $row["vald_region"];
            $vald_zip  = $row["vald_zip"];

            if($vald_fname==1) {
                $ischecked = "checked";
            }
            if($vald_lname==1) {
                $ischecked2 = "checked";
            }
            if($vald_email==1) {
                $ischecked3 = "checked";
            }
            if($vald_addr1==1) {
                $ischecked4 = "checked";
            }
            if($vald_city==1) {
                $ischecked5 = "checked";
            }
            if($vald_state==1) {
                $ischecked6 = "checked";
            }
            if($vald_count==1) {
                $ischecked7 = "checked";
            }
            if($vald_region==1) {
                $ischecked8 = "checked";
            }
            if($vald_zip==1) {
                $ischecked9 = "checked";
            }
    
        }
        $formaction = 1;
    }
    else if($action==2) {
        // no action yet
    } else {
        $formaction = 2;
    }

    $display .= "<center><form action='".e_SELF."' method='POST' name='settingsform' ID='settingsform'>
                <br />
                <table width='95%' class='fborder'>
                    <tr>
                        <td class='forumheader2' width='20%'>
                            ".lan_admin_valid_fname.": 
                        </td>
                        <td class='forumheader3'>
                            <input class=\"tbox\" type='checkbox' name='vald_fname' ".$ischecked.">
                        </td>
                    </tr>
                    <tr>
                        <td class='forumheader2' width='20%'>
                            ".lan_admin_valid_lname.": 
                        </td>
                        <td class='forumheader3'>
                            <input class=\"tbox\" type='checkbox' name='vald_lname' ".$ischecked2.">
                        </td>
                    </tr>
                    <tr>
                        <td class='forumheader2' width='20%'>
                            ".lan_admin_valid_email.": 
                        </td>
                        <td class='forumheader3'>
                            <input class=\"tbox\" type='checkbox' name='vald_email' ".$ischecked3.">
                        </td>
                    </tr>
                    <tr>
                        <td class='forumheader2' width='20%'>
                            ".lan_admin_valid_addr1.": 
                        </td>
                        <td class='forumheader3'>
                            <input class=\"tbox\" type='checkbox' name='vald_addr1' ".$ischecked4.">
                        </td>
                    </tr>
                    <tr>
                        <td class='forumheader2' width='20%'>
                            ".lan_admin_valid_city.": 
                        </td>
                        <td class='forumheader3'>
                            <input class=\"tbox\" type='checkbox' name='vald_city' ".$ischecked5.">
                        </td>
                    </tr>
                    <tr>
                        <td class='forumheader2' width='20%'>
                            ".lan_admin_valid_state.": 
                        </td>
                        <td class='forumheader3'>
                            <input class=\"tbox\" type='checkbox' name='vald_state' ".$ischecked6.">
                        </td>
                    </tr>
                    <tr>
                        <td class='forumheader2' width='20%'>
                            ".lan_admin_valid_count.": 
                        </td>
                        <td class='forumheader3'>
                            <input class=\"tbox\" type='checkbox' name='vald_count' ".$ischecked7.">
                        </td>
                    </tr>
                    <tr>
                        <td class='forumheader2' width='20%'>
                            ".lan_admin_valid_region.": 
                        </td>
                        <td class='forumheader3'>
                            <input class=\"tbox\" type='checkbox' name='vald_region' ".$ischecked8.">
                        </td>
                    </tr>
                    <tr>
                        <td class='forumheader2' width='20%'>
                            ".lan_admin_valid_zip.": 
                        </td>
                        <td class='forumheader3'>
                            <input class=\"tbox\" type='checkbox' name='vald_zip' ".$ischecked9.">
                        </td>
                    </tr>
                    <tr>
                        <td class='forumheader' colspan='2'>
                            <input class=\"tbox\" type='hidden' value='".$formaction."' name='faction'>
                            <center><input class=\"tbox\" type='submit' value='".lan_global_update."' name='subbed'></center>
                        </td>
                    </tr>

                    </form>
                    </table>";
                    $ns->tablerender("<center>".lan_admin_menu_validation."</center>", $display);
}


#####################################################
# e107shop_admin_process_category($vars)
#####################################################
# 
#    Processes the submitted details into the database
#
#####################################################
function e107shop_admin_process_validation($action, $vald_fname, $vald_lname, $vald_email, 
$vald_addr1, $vald_city, $vald_state, $vald_count, $vald_region, $vald_zip) {
    global $e107shop_db_name;
    if($vald_fname!="") {
        $vald_fname=1;
    } else {
        $vald_fname=2;
    }
    if($vald_lname!="") {
        $vald_lname=1;
    } else {
        $vald_lname=2;
    }
    if($vald_email!="") {
        $vald_email=1;
    } else {
        $vald_email=2;
    }
    if($vald_addr1!="") {
        $vald_addr1=1;
    } else {
        $vald_addr1=2;
    }
    if($vald_city!="") {
        $vald_city=1;
    } else {
        $vald_city=2;
    }
    if($vald_state!="") {
        $vald_state=1;
    } else {
        $vald_state=2;
    }
    if($vald_count!="") {
        $vald_count=1;
    } else {
        $vald_count=2;
    }
    if($vald_region!="") {
        $vald_region=1;
    } else {
        $vald_region=2;
    }
    if($vald_zip!="") {
        $vald_zip=1;
    } else {
        $vald_zip=2;
    }
    global $sql, $ns;
    if($action==1) {
        //
        // Change admin settings
        //
        $sql->db_Update($e107shop_db_name['validate'], "vald_fname='".$vald_fname."', vald_lname='".
        $vald_lname."', vald_email='".$vald_email."', vald_addr1='"
        .$vald_addr1."', vald_city='".$vald_city."', vald_state="
        .$vald_state.", vald_count='".$vald_count."', vald_region='"
        .$vald_region."', vald_zip='".$vald_zip."'");
        $ns->tablerender("<center>".lan_global_status."</center>", 
        "<center>".lan_global_updated."</center>");
    } else {
        //
        // Insert new settings
        //
        $sql->db_Insert($e107shop_db_name['validate'], "'".$vald_fname."', '".$vald_lname."', '".
        $vald_email."', '".$vald_addr1."', '".$vald_city."', '".$vald_state."', '".
        $vald_count."', '".$vald_region."', '".$vald_zip."'");

        $ns->tablerender("<center>".lan_global_status."</center>", 
        "<center><br />".lan_global_inserted."</center>");

    }
}



require_once(e_ADMIN."footer.php");
